using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Service.Business.IBusinessService;
using JTZY.Admin.WebApi.Filters;
using Aliyun.OSS;

//创建时间：2025-02-05
namespace JTZY.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// 商品浏览记录表
    /// </summary>
    [Verify]
    [Route("business/Corecmsgoodsbrowsing")]
    public class CorecmsgoodsbrowsingController : BaseController
    {
        /// <summary>
        /// 商品浏览记录表接口
        /// </summary>
        private readonly ICorecmsgoodsbrowsingService _CorecmsgoodsbrowsingService;

        public CorecmsgoodsbrowsingController(ICorecmsgoodsbrowsingService CorecmsgoodsbrowsingService)
        {
            _CorecmsgoodsbrowsingService = CorecmsgoodsbrowsingService;
        }

        /// <summary>
        /// 查询商品浏览记录表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsgoodsbrowsing:list")]
        public IActionResult QueryCorecmsgoodsbrowsing([FromQuery] CorecmsgoodsbrowsingQueryDto parm)
        {
            var response = _CorecmsgoodsbrowsingService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询商品浏览记录表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsgoodsbrowsing:query")]
        public IActionResult GetCorecmsgoodsbrowsing(int Id)
        {
            var response = _CorecmsgoodsbrowsingService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsgoodsbrowsingDto>();
            return SUCCESS(info);
        }


        [HttpGet("getuservisit")]
        [ActionPermissionFilter(Permission = "corecmsgoodsbrowsing:query")]
        public IActionResult Getuservisit(CorecmsgoodsbrowsingQueryDto parm)
        {
            var response = _CorecmsgoodsbrowsingService.GetUserVisit(parm);

            return SUCCESS(response);
        }

        /// <summary>
        /// 添加商品浏览记录表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsgoodsbrowsing:add")]
        [Log(Title = "商品浏览记录表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsgoodsbrowsing([FromBody] CorecmsgoodsbrowsingDto parm)
        {
            var modal = parm.Adapt<Corecmsgoodsbrowsing>().ToCreate(HttpContext);

            var response = _CorecmsgoodsbrowsingService.AddCorecmsgoodsbrowsing(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新商品浏览记录表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsgoodsbrowsing:edit")]
        [Log(Title = "商品浏览记录表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsgoodsbrowsing([FromBody] CorecmsgoodsbrowsingDto parm)
        {
            var modal = parm.Adapt<Corecmsgoodsbrowsing>().ToUpdate(HttpContext);
            var response = _CorecmsgoodsbrowsingService.UpdateCorecmsgoodsbrowsing(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除商品浏览记录表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsgoodsbrowsing:delete")]
        [Log(Title = "商品浏览记录表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsgoodsbrowsing([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsgoodsbrowsingService.Delete(idArr));
        }

    }
}